---
category: String
created: '2020-05-15'
title: Convert a string to PascalCase
updated: '2021-10-13'
---

**JavaScript version**

```js toPascalCase.js
const toPascalCase = (str) =>
    (str.match(/[a-zA-Z0-9]+/g) || []).map((w) => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join('');
```

**TypeScript version**

```ts toPascalCase.ts
const toPascalCase = (str: string): string =>
    (str.match(/[a-zA-Z0-9]+/g) || []).map((w) => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join('');
```

**Examples**

```js examples.js
toPascalCase('hello world'); // 'HelloWorld'
toPascalCase('hello.world'); // 'HelloWorld'
toPascalCase('foo_bar-baz'); // FooBarBaz
```
